package com.huanghao.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.huanghao.Service.OrderService;
import com.huanghao.pojo.Commod;
import com.huanghao.pojo.Order;
import com.huanghao.pojo.PageBean;
import com.huanghao.pojo.Result;

@RestController
public class OrderController {

	@Autowired
	private com.huanghao.Service.OrderService orderService;
	
    //根据商品名查询  成功
    @GetMapping("orderser.do")
    public Result page(@RequestParam(defaultValue = "1") Integer page,
    													@RequestParam(defaultValue = "10") Integer pageSize,
    													String name,String user){
    	System.out.println("查询信息");
        PageBean order	= orderService.page(page,pageSize,name,user);
        return Result.success(order);
    }
    
    //根据ID查询 成功
    @GetMapping("orderser.do/{id}")
    public Result getById(@PathVariable Integer id){
    	System.out.println("查询id为"+id+"的信息");
        Order order  = orderService.getById(id);
        return Result.success(order);
    }
    
    //删除
    @DeleteMapping("orderser.do/{oNumber}")
    public Result delete(@PathVariable  List<Integer> oNumber) {
		System.out.println("删除订单");
		orderService.delete(oNumber);
		return Result.success();
    }
    
	//新增
    @PostMapping("orderser.do")
    public Result add(  Order order) {
		System.out.println("增加订单: ");
		orderService.add(order);
		return Result.success();
    }
    
    //更新 完成
    @PutMapping("orderser.do")
    public  Result update( Order order){
    	System.out.println("更新订单");
        orderService.update(order);
        return Result.success();
    }
}
